home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / dom / ElementImpl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  3.7 KB  |  196 lines

  1. package com.ibm.xml.dom;
  2.  
  3. import org.w3c.dom.Attr;
  4. import org.w3c.dom.DOMException;
  5. import org.w3c.dom.Element;
  6. import org.w3c.dom.NamedNodeMap;
  7. import org.w3c.dom.Node;
  8. import org.w3c.dom.NodeList;
  9. import org.w3c.dom.Text;
  10.  
  11. public class ElementImpl extends NodeImpl implements Element {
  12.    static final long serialVersionUID = -7202454486126245907L;
  13.    protected NamedNodeMapImpl attributes;
  14.  
  15.    public ElementImpl(DocumentImpl var1, String var2) {
  16.       super(var1, var2, (String)null);
  17.       super.syncData = true;
  18.    }
  19.  
  20.    public short getNodeType() {
  21.       return 1;
  22.    }
  23.  
  24.    public String getNodeValue() {
  25.       return null;
  26.    }
  27.  
  28.    public void setNodeValue(String var1) throws DOMException {
  29.       throw new DOMExceptionImpl((short)7, (String)null);
  30.    }
  31.  
  32.    public NamedNodeMap getAttributes() {
  33.       if (super.syncData) {
  34.          this.synchronizeData();
  35.       }
  36.  
  37.       return this.attributes;
  38.    }
  39.  
  40.    public Node cloneNode(boolean var1) {
  41.       if (super.syncData) {
  42.          this.synchronizeData();
  43.       }
  44.  
  45.       ElementImpl var2 = (ElementImpl)super.cloneNode(var1);
  46.       var2.attributes = this.attributes.cloneMap();
  47.       return var2;
  48.    }
  49.  
  50.    public String getValue() {
  51.       return null;
  52.    }
  53.  
  54.    public String getAttribute(String var1) {
  55.       if (super.syncData) {
  56.          this.synchronizeData();
  57.       }
  58.  
  59.       Attr var2 = (Attr)this.attributes.getNamedItem(var1);
  60.       return var2 == null ? "" : var2.getValue();
  61.    }
  62.  
  63.    public Attr getAttributeNode(String var1) {
  64.       if (super.syncData) {
  65.          this.synchronizeData();
  66.       }
  67.  
  68.       return (Attr)this.attributes.getNamedItem(var1);
  69.    }
  70.  
  71.    public NodeList getElementsByTagName(String var1) {
  72.       return new DeepNodeListImpl(this, var1);
  73.    }
  74.  
  75.    public String getTagName() {
  76.       if (super.syncData) {
  77.          this.synchronizeData();
  78.       }
  79.  
  80.       return super.name;
  81.    }
  82.  
  83.    public void normalize() {
  84.       Node var2;
  85.       for(Node var1 = ((NodeImpl)this).getFirstChild(); var1 != null; var1 = var2) {
  86.          var2 = var1.getNextSibling();
  87.          if (var2 != null && var1.getNodeType() == 3 && var2.getNodeType() == 3) {
  88.             ((Text)var1).appendData(var2.getNodeValue());
  89.             ((NodeImpl)this).removeChild(var2);
  90.             var2 = var1;
  91.          } else if (var1.getNodeType() == 1) {
  92.             ((Element)var1).normalize();
  93.          }
  94.       }
  95.  
  96.    }
  97.  
  98.    public void removeAttribute(String var1) {
  99.       if (super.readOnly) {
  100.          throw new DOMExceptionImpl((short)7, (String)null);
  101.       } else {
  102.          if (super.syncData) {
  103.             this.synchronizeData();
  104.          }
  105.  
  106.          AttrImpl var2 = (AttrImpl)this.attributes.getNamedItem(var1);
  107.          if (var2 != null) {
  108.             var2.owned = false;
  109.             this.attributes.removeNamedItem(var1);
  110.          }
  111.  
  112.       }
  113.    }
  114.  
  115.    public Attr removeAttributeNode(Attr var1) throws DOMException {
  116.       if (super.readOnly) {
  117.          throw new DOMExceptionImpl((short)7, (String)null);
  118.       } else {
  119.          if (super.syncData) {
  120.             this.synchronizeData();
  121.          }
  122.  
  123.          AttrImpl var2 = (AttrImpl)this.attributes.getNamedItem(var1.getName());
  124.          if (var2 == var1) {
  125.             this.attributes.removeNamedItem(var1.getName());
  126.             var2.owned = false;
  127.             return var2;
  128.          } else {
  129.             throw new DOMExceptionImpl((short)8, (String)null);
  130.          }
  131.       }
  132.    }
  133.  
  134.    public void setAttribute(String var1, String var2) {
  135.       if (super.readOnly) {
  136.          throw new DOMExceptionImpl((short)7, (String)null);
  137.       } else {
  138.          if (super.syncData) {
  139.             this.synchronizeData();
  140.          }
  141.  
  142.          AttrImpl var3 = (AttrImpl)((NodeImpl)this).getOwnerDocument().createAttribute(var1);
  143.          var3.setNodeValue(var2);
  144.          this.attributes.setNamedItem(var3);
  145.          var3.owned = true;
  146.       }
  147.    }
  148.  
  149.    public Attr setAttributeNode(Attr var1) throws DOMException {
  150.       if (super.readOnly) {
  151.          throw new DOMExceptionImpl((short)7, (String)null);
  152.       } else {
  153.          if (super.syncData) {
  154.             this.synchronizeData();
  155.          }
  156.  
  157.          if (!(var1 instanceof AttrImpl)) {
  158.             throw new DOMExceptionImpl((short)4, (String)null);
  159.          } else {
  160.             AttrImpl var2 = (AttrImpl)var1;
  161.             AttrImpl var3 = (AttrImpl)this.attributes.getNamedItem(var1.getName());
  162.             this.attributes.setNamedItem(var2);
  163.             var2.owned = true;
  164.             return var3;
  165.          }
  166.       }
  167.    }
  168.  
  169.    public void setReadOnly(boolean var1, boolean var2) {
  170.       super.setReadOnly(var1, var2);
  171.       if (super.syncChildren) {
  172.          ((NodeImpl)this).synchronizeChildren();
  173.       }
  174.  
  175.       this.attributes.setReadOnly(var1, true);
  176.    }
  177.  
  178.    protected void synchronizeData() {
  179.       super.syncData = false;
  180.       this.setupDefaultAttributes();
  181.    }
  182.  
  183.    protected void setupDefaultAttributes() {
  184.       NamedNodeMapImpl var1 = null;
  185.       DocumentTypeImpl var2 = (DocumentTypeImpl)super.ownerDocument.getDoctype();
  186.       if (var2 != null) {
  187.          ElementDefinitionImpl var3 = (ElementDefinitionImpl)var2.getElements().getNamedItem(((NodeImpl)this).getNodeName());
  188.          if (var3 != null) {
  189.             var1 = (NamedNodeMapImpl)var3.getAttributes();
  190.          }
  191.       }
  192.  
  193.       this.attributes = new NamedNodeMapImpl(this, var1);
  194.    }
  195. }
  196.